package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

/**
 * 鼠标右键菜单选项
 * @author rebin
 *
 */
public class MousMenuItem extends BodyNokaTag{
	private static final long serialVersionUID = -724238550089778899L;
	private String style = "-moz-border-radius:3px;border-radius:3px;";
	private String classStyle="";
	private String jsfunction=null;
	public int doStartTag() throws JspException {
		return EVAL_BODY_BUFFERED;
	}
    public int doAfterBody() throws JspException {
		StringBuilder body = new StringBuilder();
		BodyContent bodyc = this.getBodyContent();
        String    content = null;
        if(bodyc!=null){
        	content=bodyc.getString();
        }
		Tag tag = getParent();
		if(tag!=null && tag instanceof MousRightMenu && content!=null){
			MousRightMenu fh = (MousRightMenu)tag;
			body.append("<div id=\""+fh.getMenuItemID()+"\" onclick=\""+jsfunction+"()\" class=\""+classStyle+"\" style=\"cursor: pointer;width:"+LenFormat(fh.getWidth())+";"+style+"\">"+content+"</div>");
			try {
				bodyc.clearBody();
				bodyc.write(body.toString());
		        setBodyContent(bodyc);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return SKIP_BODY;
	}
    public int doEndTag()throws JspException{  
        if(super.bodyContent!=null){  
            try{  
                super.bodyContent.writeOut(super.getPreviousOut());    //输出到页面  
            }  
            catch(Exception e){}  
        }  
        return BodyTagSupport.EVAL_PAGE;  
    }
	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getClassStyle() {
		return classStyle;
	}

	public void setClassStyle(String classStyle) {
		this.classStyle = classStyle;
	}

	public String getJsfunction() {
		return jsfunction;
	}

	public void setJsfunction(String jsfunction) {
		this.jsfunction = jsfunction;
	}
}
